package com.easidea.tim.dao.saleorder;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springside.core.dao.extend.HibernateEntityExtendDao;

import com.easidea.tim.entity.saleorder.SaleOrderItem;

public class SaleOrderItemDao extends HibernateEntityExtendDao<SaleOrderItem>{

	 public void deleteItemsByOrderId(long orderId) {
			List<SaleOrderItem> items = this.getItemsByOrderId(orderId);
			this.getHibernateTemplate().deleteAll(items);
		 }
		 public void saveSaleOrderItem(SaleOrderItem item){
			 this.getHibernateTemplate().save(item);
		 }
		 @SuppressWarnings("unchecked")
		public List<SaleOrderItem> getItemsByOrderId(long orderId) {
			 Criteria ca = this.createUnDeletedCriteria();
			 ca.add(Restrictions.eq("saleOrder.id", orderId));
			 List result = ca.list();
			 return result;
		 }
		 
		 public List<SaleOrderItem> getItemsById(long orderId) {
			 Criteria ca = this.createUnDeletedCriteria();
			 ca.add(Restrictions.eq("id", orderId));
			 List result = ca.list();
			 return result;
		 }
		 
		 public boolean UpdateSaleOrderItem(SaleOrderItem orderItem){
			 this.getHibernateTemplate().update(orderItem);
			 return true;
		 }
		 
}
